﻿namespace ObserverDemo
{
    internal class Publisher : ISubject
    {
        private string name;
        private List<IObserver> observers;

        public string Name => name;

        public Publisher(string name)
        {
            this.name = name;
            observers = new List<IObserver>();
        }

        public void Notify(string message)
        {
            foreach (var observer in observers)
            {
                observer.Update(this, message);
            }
        }

        public void Subscribe(IObserver observer)
        {
            observers.Add(observer);
        }

        public void Unsubscribe(IObserver observer)
        {
            observers.Remove(observer);
        }
    }
}
